function changeVirtualCurrencyType() {
	document.getElementById("showVirtualType").className = "changedOver";
	document.getElementById("virtualTypeBg").className = "caretBlack";
	document.getElementById("hideVirtualType").style.display = "";
}
function changeBgStyle() {
	document.getElementById("showVirtualType").className = "changedOver";
	document.getElementById("virtualTypeBg").className = "caretBlack";
	document.getElementById("hideVirtualType").style.display = "";
}
function resumeBgStyle() {
	document.getElementById("showVirtualType").className = "changed";
	document.getElementById("virtualTypeBg").className = "careticon";
	document.getElementById("hideVirtualType").style.display = "none";
}
//-----------------cookies file -----------------------//
function CookieClass()
{
	this.expires = 60*24*7 ; //有效时间,以分钟为单位 
	this.path = ""; //设置访问路径 
	this.domain = ""; //设置访问主机 
	this.secure = false; //设置安全性

	this.setCookie = function(name,value)
	{ 
	   var str = name+"="+escape(value); 
	   if (this.expires>0)
	   { 
	    //如果设置了过期时间 
	    var date=new Date(); 
	    var ms=this.expires * 60 * 1000; //每分钟有60秒，每秒1000毫秒 
	    date.setTime(date.getTime()+ms); 
	    str+="; expires="+date.toGMTString(); 
	   } 
	   str+="; path=/";
	   //if(this.path!="")str+="; path=/";//+this.path; //设置访问路径 
	   if(this.domain!="")str+="; domain="+this.domain; //设置访问主机 
	   if(this.secure!="")str+="; true"; //设置安全性
	   document.cookie=str; 
	};

	this.getCookie=function(name)
	{ 
	   var cookieArray=document.cookie.split("; "); //得到分割的cookie名值对 
	   //var cookie=new Object(); 
	   for(var i=0;i<cookieArray.length;i++)
	   { 
	    var arr=cookieArray[i].split("="); //将名和值分开 
	    if(arr[0]==name)return unescape(arr[1]); //如果是指定的cookie，则返回它的值 
	   } 
	   return ""; 
	};

	this.deleteCookie=function(name)
	{ 
	   var date=new Date(); 
	   var ms= 1 * 1000; 
	   date.setTime(date.getTime() - ms); 
	   var str = name+"=no; expires=" + date.toGMTString(); //将过期时间设置为过去来删除一个cookie 
	   document.cookie=str; 
	};

	this.showCookie=function()
	{ 
	   alert(unescape(document.cookie)); 
	};
}

//使用例子 
//var cook = new CookieClass(); 
//cook.expires =1;//一分钟有效 
//cook.setCookie("01","5556666666666555");//写 
//alert(cook.getCookie("01"));//读 
//cook.showCookie();

//-----------------cookies file end-----------------------//
function getLanguageCookie(elem){
	var languageCookie = new CookieClass();
	languageCookie.domain = ".okcoin.cn";
	languageCookie.setCookie("language", elem);
	var languageCookie2 = new CookieClass();
	languageCookie2.domain = ".oklink.com";
	languageCookie2.setCookie("language", elem);
	var ref=window.location.href;
	if(ref.indexOf("#")!=-1){
		var str=ref.substring(0,ref.indexOf("#"));
		window.location.href = str;
	}else{
		window.location.href = ref;
	}
}

/**
 * 浮动块的显示和隐藏
 */
function boxFloat(obj,elem){
	var nmove,mmove,
		d = document,
		o = d.getElementById(obj),
		s = d.getElementById(elem);
	if(!o){ return false;}
	if(!s){ return false;}
	
	s.onmouseover=function(){
		clearTimeout(nmove);
		s.style.display="block";
		s.style.cursor="pointer";
	};
	o.onmouseover=function(){
		clearTimeout(nmove);
		mmove=setTimeout(function(){
			s.style.display="block";
		},100);
		
	};
	o.onmouseout=function(){
		clearTimeout(mmove);
		nmove=setTimeout(function(){s.style.display="none";},500);
	};
	s.onmouseout=function(){
		nmove=setTimeout(function(){s.style.display="none";},500);
	};
//	s.onmousedown=function(e){
//		stopBubble(e);
//	};
}
boxFloat("languageTypeStyle","languageTypeStyleId");

/**
 * 时间单位根据语言的转化
 */
function getDataStrByLan(type){
	
	var dataStr = "";
	var languageCookieType = new CookieClass();
	var language = languageCookieType.getCookie("language");
	var lanType = (navigator.systemLanguage?navigator.systemLanguage:navigator.language);
	if(language == "en_us" || (!language && lanType.indexOf("zh") == -1)){ //英文
		switch(type){
			case "days":
				dataStr = "days"; break;
			case "day":
				dataStr = "day"; break;
			case "hours":
				dataStr = "hours"; break;
			case "hour":
				dataStr = "hour"; break;
			case "minutes":
				dataStr = "minutes"; break;
			case "minute":
				dataStr = "minute"; break;
			default:
				dataStr = "";
		}
	}else if(language == "zh_tw"){
		switch(type){
			case "days":
			case "day":
				dataStr = "天"; break;
			case "hours":
			case "hour":
				dataStr = "小時"; break;
			case "minutes":
			case "minute":
				dataStr = "分鐘"; break;
			default:
				dataStr = "";
			
		}
	}
	else{
		switch(type){
			case "days":
			case "day":
				dataStr = "天"; break;
			case "hours":
			case "hour":
				dataStr = "小时"; break;
			case "minutes":
			case "minute":
				dataStr = "分钟"; break;
			default:
				dataStr = "";
		}
	}
	return dataStr;
}

/**
 * 页面回到顶部图标的显示和隐藏
 */
$(window).scroll(function(){
	if ($(window).scrollTop()>100){
		$("#back-to-top").fadeIn(1000);
	} else {
		$("#back-to-top").fadeOut(1000);
	}
});
/**
 * 点击后页面自动回到顶部
 */
$('#back-to-top').bind('click', function() {
	$('body,html').animate({scrollTop:0},200);
	return false;
});

/**
 * 地址页面中超过10条的点击显示全部内容
 */
$(".more-content").bind('click', function() {
	$(this).hide();
	$(this).parents("td").find(".hide-content").show(2000);
});

/**
 * 顶部和首面搜索按钮的事件
 */
$(".search-img").bind('click', function() {
	topSearch(1);
});
$(".search-query").keydown(function(event) {
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && (e.keyCode == 13 || e.which == 13)){ // enter 键
		topSearch(1);
	}
});
//$("#search_button").bind('click', function() {
//	topSearch(2);
//});
$("#search_input2").keydown(function(event) {
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && (e.keyCode == 13 || e.which == 13)){ // enter 键
		topSearch(2);
	}
});

/**
 * 搜索功能的实现，type=1顶部搜索，type=2首面中的搜索
 */
function topSearch(type){
	var search = $(".search-query").val();
	if(type == 2){
		search = $("#search_input2").val();
	}
//	var ref = window.location.href;
//	var str = ref.substring(0,ref.indexOf("/"));
	var symbol = "btc";
	if($(".showType").html() == "LTC"){
		symbol = "ltc";
	}
	var languageCookieType = new CookieClass();
	var language = languageCookieType.getCookie("language");
	var title = "请先输入搜索内容";
	if(language == 1 || language == "en_us" ) {
		title = "Please enter search content";
	}
	
	var reg = /^\s*$/;
	if(reg.test(search)){
		if(!$("#searchTitle").html()){
			$(".navbar").append('<div id="searchTitle" class="alert alert-error"><h4>' + title 
					+ '<span class="alert-close">X<span></h4></div>');
			//关闭提示信息
			$(".alert-close").bind('click', function() {
				$("#searchTitle").remove();
			});
		}
	}else{
		$("#searchTitle").hide();
		window.location.href = root + symbol + "/search/" + search +"/";
	}
}


$(document).on("click",".more-btn",function(){

    $(this).html("加载中");
    var p = $(this).attr("bl-p");
    var url = $(this).attr("bl-url")+"?p="+p;

    var thisDiv = $(this).parent();

    $.post(url,null,function(data){

        if (data != null) {
            $(thisDiv).remove();
            $("#txContent").append(data);
        }
    });

});


$(document).on("click",".tx_detail",function(){

    $(this).html("加载中...")

    var url = $(this).attr("tx-url");
    var type = $(this).attr("tx-type");
    // 3:未确认交易记录列表页面。
    var pageType = $(this).attr("show-type");

    var symbol = $("#symbol").val();
    var symbolStr = symbol == 0? "BTC" : "LTC";
    var addrBase58 = $("#addrBase58").val();
    var thisDiv = $(this).parent();
    var param = {type:type};

    $.post(url,param,function(data){
        var result = eval('(' + data + ')');
        if (result != null) {

            var code = result.errorCode;
            if (code == 1) {
                var array = result.list;

                var html = "";
                if (type == 1) {// in
                    for (var i=0; i< array.length; i++) {
                        var txin= array[i];

                        var addr = txin.addr;
                        var isBase = txin.isBase;
                        var volume = txin.volume_s;
                        var volume_c = txin.volume_c;
                        if (isBase == 1) {//新区块奖励
                            html+="<b>"+addr+"</b><br/>"
                        } else {
                            if (addr == addrBase58) {//跟查询地址相同的
                                html+="<span style=\"color: gray\">"+addr+"</span>";
                                html+="(<span data-c=\""+volume+"\" data-time=\"\">"+volume + " " + symbolStr+"</span>)<br />";
                            } else {//普通地址
                                html+="<a href=\"/"+symbol+"/address/"+addr+"\">"+addr+"</a>";
                                html+="(<span data-c=\""+volume_c+"\" data-time=\"\">"+volume + " " + symbolStr+"</span>)<br />";
                            }
                        }
                    }
                } else if (type == 2) { //out
                    for (var i=0;i < array.length; i++) {
                        var txout = array[i];
                        var addr = txout.addr;
                        var isSend = txout.isSend;
                        var sendCss = isSend == 1 ? "red" : "green";
                        var volume = txout.volume_s;
                        var volume_c = txout.volume_c;
                        var txTime = txout.txTime;
                        
                        if(pageType == 3){
                        	html += "<a href=\"/btc/address/" + addr + "\">" + addr + "</a>";
                            html += "<span class=\"pull-right hidden-phone\">";
                            html += "<span data-c=\""+volume_c+"\" data-time=\""+txTime+"\">"+volume + " " + symbolStr+"</span></span><br />";
                        } else {
                        	if (isSend == -1) {
                                html+= addr+" - "+"(<font color=\"gray\">"+txout.isSendStr+"</font>)";
                            } else {
                                html+= addr+" - "+"(<font color=\""+sendCss+"\">"+txout.isSendStr+"</font>)"
                            }

                            html+="<span class=\"pull-right hidden-phone\">";
                            html+="<span data-c=\""+volume_c+"\" data-time=\""+txTime+"\">"+volume+" "+symbolStr+"</span></span><br />";
                        }
                    }
                }

                $(thisDiv).empty()
                $(thisDiv).append(html);
            }
        }
    });

});